<template>
	<view class="p-l-30 p-r-30 p-t-38 p-b-20" >
		<view class=" bg-white  " v-for="(item,index) in list">
			<view class="m-b-16" style="height: 80upx;line-height: 80upx;" @click="fatherClick(index)" >
				{{item.name}}
			</view>
			<block v-if="isActive==index &&(index != list.length-1) ">
				<view :class="itemActive==item2.id?'active item':'item'" @click="itemClick" :data-id="item2.id" :data-father="item.id"  v-for="item2 in item.reason">
					{{item2.detail}}
				</view>
			</block>
			<block v-if="isActive==index &&(index == list.length-1) ">
				<view style="background-color: #F9F9F9 ;border-radius: 20rpx; overflow: hidden; " class="p-30">
					
			
				<u-input  v-model="otherModel" type="textarea" placeholder="以上都不是？偷偷告诉我们原因吧。填写内容我们会严格匿名，请放心填写。" :border="true" height="180" @change="inputChange" >
					
				</u-input>
				<view class="flex " style="color:#C3C3C3;width: 100%;justify-content: flex-end;">
					{{otherModel.length}}/60
				</view>
			</view>
			</block>
				
		</view>
		
	</view>
</template>

<script>
	export default {
		name:"reason-list",
		data() {
			return {
				isActive:0,
				otherModel:'',
				time:null
			};
		},
		onUnload() {
			clearTimeout(this.time)
		},
		props:['list','itemActive'],
		methods:{
			itemClick(e){
				console.log(e)
				let id = e.currentTarget.dataset.id;
				let father =  e.currentTarget.dataset.father
				this.$emit('itemClick',{id,father})
			},
			fatherClick(index){
				this.isActive = index;
				this.$emit('fatherClick')
			},
		},
		watch:{
			otherModel(val){
				this.time = setTimeout(()=>{
					this.$emit('inputChange',!!val)
				},300)
			}
		}
		
	}
</script>

<style lang="scss">
	.item{
		height: 80upx;
		line-height: 80upx;
		color: #6C6969;
		background-color: #F9F9F9 ;
		border-radius: 8upx;
		margin-bottom: 20upx;
		padding: 0 20upx;
		border: 1upx solid #F7F3F3;
	}
	.active{
		background-color: #E8563110;
		color: #E85631;
	}
</style>
